/**
* @desc desc
* @author 钱炜亮
* @date 2024-04-21
*/
<template>
  <common-page>
    <view class="page-box-company">
			<u--form
				labelPosition="left"
				labelWidth="180rpx"
				:model="formData"
				:rules="rules"
				ref="uForm"
			>
				<u-form-item
					label="设备名称"
					prop="deviceName"
					borderBottom
				>
					<view>{{ formData.deviceName }}</view>
				</u-form-item>
				<u-form-item
					label="预警联系人"
					prop="linkManList.linkName"
					borderBottom
					required
				>
					<u--input
						v-model="formData.linkManList.linkName"
						border="none"
						placeholder="请填写预警联系人"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
				<u-form-item
					label="联系人手机"
					prop="linkManList.linkPhone"
					borderBottom
					required
				>
					<u--input
						v-model="formData.linkManList.linkPhone"
						border="none"
						placeholder="请填写联系人手机"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
			</u--form>
    </view>
		<u-button text="保存" type="primary" color="#417CE9" @click="bindSubmit"></u-button>
  </common-page>
</template>

<script>
export default {
	data() {
		return {
			formData: {
				deviceName: '',
				id: '',
				linkManList: {
					linkName: '',
					linkPhone: '',
				}
			},
			rules: {
				'linkManList.linkName': {
					type: 'string',
					required: true,
					message: '请填写预警联系人',
					trigger: ['blur', 'change']
				},
				'linkManList.linkPhone': [{
					type: 'string',
					required: true,
					message: '请填写联系人电话',
					trigger: ['blur', 'change']
				}, {
					pattern: /^1[3-9]\d{9}$/,
					message: '请填写正确手机号格式',
					trigger: ['blur']
				}]
			}
		};
	},
	onLoad(option) {
		console.log(option.deviceSn)
		this.getDeviceInfoData(option.deviceSn);
	},
	methods: {
		// 获取公司详情
		async getDeviceInfoData(deviceSn) {
			const params = {
				deviceSn: deviceSn,
			}
			const [err, result] = await this.$to(uni.$u.http.post('/jeecg-boot/api/v1-public/mini-program-device/getDeviceInfo',params));
			if (err) return;
			console.log(result)
			this.formData = {
				deviceName: result.deviceName,
				id: result.id,
				linkManList: {
					linkName: result.linkName,
					linkPhone: result.linkPhone,
				}
			};
		},
		bindSubmit() {
			this.$refs.uForm.validate().then(async(res) => {
				const [err, result] = await this.$to(uni.$u.http.post('/jeecg-boot/api/v1-public/mini-program-device/updateLinkMan', this.formData));
				if (err) return;
				uni.$u.toast('修改成功');
				setTimeout(() => {
					uni.navigateBack();
				}, 1500);
			}).catch(errors => {
				uni.$u.toast('校验失败');
			});
		}
		/* ====== S 事件区域 ====== */

		/* ====== E 事件区域 ====== */
		/* ====== S 通用逻辑 ====== */

		/* ====== E 通用逻辑 ====== */
		/* ====== S 接口定义 ====== */

		/* ====== E 接口定义 ====== */
	}
};
</script>

<style>

</style>
<style lang="scss" scoped>
.page-box-company {
	background-color: #fff;
	border-radius: 20rpx;
	margin-top: 32rpx;
	padding: 20rpx 40rpx;

}

::v-deep .u-button {
	margin-top: 60rpx;
	border-radius: 80rpx !important;
	.u-button__text {
		font-size: 32rpx !important;
		font-weight: bold;
	}
}
</style>
